package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// Gift holds the schema definition for the Gift entity.
type Gift struct {
	ent.Schema
}

// Fields of the Gift.
func (Gift) Fields() []ent.Field {
	return []ent.Field{
		field.String("title").
			NotEmpty().
			Comment("标题"),
		field.Text("description").
			Optional().
			Comment("描述"),
		field.String("image_url").
			Optional().
			Comment("图片URL"),
		field.Float("price").
			Optional().
			Comment("价格"),
		field.String("status").
			Default("想要").
			Comment("状态：想要/已送/已收"),
		field.Int64("from_user_id").
			Optional().
			Nillable().
			Comment("赠送者ID"),
		field.Int64("to_user_id").
			Comment("接收者ID"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the Gift.
func (Gift) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("from_user", User.Type).
			Ref("sent_gifts").
			Field("from_user_id").
			Unique(),
		edge.From("to_user", User.Type).
			Ref("received_gifts").
			Field("to_user_id").
			Unique().
			Required(),
	}
}
